package edu.hz.dao;

import edu.hz.model.entity.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {

    @Insert("INSERT INTO users(username, student_id, realname, pwd, pwd_salt, gender, grade_id, clazz_id, money, title, err_login_count) " +
            "VALUES(#{username}, #{studentId}, #{realname}, #{pwd}, #{pwdSalt}, #{gender}, #{gradeId}, #{clazzId}, #{money}, #{title}, #{errLoginCount})")
    int insertUser(UserEntity user);

    @Select("SELECT * FROM users WHERE username = #{username}")
    UserEntity getUserByUsername(String username);

    @Select("SELECT * FROM users WHERE id = #{id}")
    UserEntity getUserById(int id);

    @Select("SELECT * FROM users")
    List<UserEntity> getAllUsers();

    @Update("UPDATE users SET err_login_count = #{errLoginCount} WHERE id = #{id}")
    int updateErrLoginCount(@Param("id") int id, @Param("errLoginCount") int errLoginCount);

}
